package com.hllxd.hism.star.basic.service.controller2;

import com.hllxd.hism.framework.httprpc.service.*;
import com.hllxd.hism.star.basic.service.exception.BusinessException;
import com.hllxd.hism.star.basic.service.service.FengkongService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author xiyong.lxy
 * @date 2022-03-13 16:51
 */
@Slf4j
@RestGrpcService
@RestGrpcMapping("/v1/fengkong")
public class FengkongController2 {

    @Autowired
    private FengkongService fengkongService;

    @Data
    public static class Params {
        public String dt;
    }

    @RestGrpcMapping("/loadDashboard.do")
    public NTSTATUS loadDashboard(PDRIVER_OBJECT params, PRESULT_OBJECT result) {
        log.info("params: {}", params);
        try {
            Params aa = params.driverObject(Params.class);
            result.setData(fengkongService.loadDashboard(aa.dt));
            return NTSTATUS.SUCCESS_STATUS();
        } catch (BusinessException e) {
            log.warn("Exception: {}. {}", e, params);
            return NTSTATUS.ERROR_STATUS(e.code, e.msg);
        } catch (Exception e) {
            log.error("Exception: {}. {}", e, params, e);
            return NTSTATUS.ERROR_STATUS("500", e.toString());
        }
    }

    @RestGrpcMapping("/readFengkongV2.do")
    public NTSTATUS readFengkongV2(PDRIVER_OBJECT params, PRESULT_OBJECT result) {
        log.info("params: {}", params);
        try {
            Params aa = params.driverObject(Params.class);
            result.setData(fengkongService.readFengkongV2(aa.dt));
            return NTSTATUS.SUCCESS_STATUS();
        } catch (BusinessException e) {
            log.warn("Exception: {}. {}", e, params);
            return NTSTATUS.ERROR_STATUS(e.code, e.msg);
        } catch (Exception e) {
            log.error("Exception: {}. {}", e, params, e);
            return NTSTATUS.ERROR_STATUS("500", e.toString());
        }
    }
}
